﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style>
a {
	padding-right: 15px;
	text-decoration: blink;
}
</style>
<div style="margin: 20px 0;">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		onclick="$('#addmember').window('open')">新增会员</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="editer()">修改</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="saver()">保存</a>
	<!-- 		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="edit()">编辑会员</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()">保存会员</a> -->
</div>
<div style="margin: 20px 0;"></div>
<table id="member" class="easyui-treegrid" title="推广人列表"
	style="width: 100%; height: 500px"
	data-options="
				iconCls: 'icon-ok',
				rownumbers: true,
				animate: true,
				collapsible: true,
				fitColumns: true,
				url: './member/list',
				method: 'get',	
				idField: 'id',
				treeField: 'text',
				onContextMenu: onContextMenu
			">
	<thead>
		<tr>
			<th data-options="field:'text',width:60,editor:'text'">会员名称</th>
			<th data-options="field:'memberno',width:80,editor:'text'">会员微信号</th>
			<th data-options="field:'tel',width:80,editor:'text'">电话号码</th>
			<th data-options="field:'job',width:120,editor:'text'">职业</th>
			<th data-options="field:'sex',width:40,editor:'text'">性别</th>
			<th data-options="field:'provice',width:80,editor:'text'">省份</th>
			<th data-options="field:'city',width:120,editor:'text'">城市</th>
			<th data-options="field:'vipcode',width:80,editor:'text'">会员推荐码</th>
			<th data-options="field:'level',width:80,editor:'text'">推广等级</th>
			<th
				data-options="field:'created',width:130,align:'center',formatter:TAOTAO.formatDateTime">创建日期</th>
			<th
				data-options="field:'updated',width:130,align:'center',formatter:TAOTAO.formatDateTime">更新日期</th>
		</tr>
	</thead>
</table>

<!-- 	<div id="memberchilendtool" class="easyui-menu" style="width:120px;">
		<div onclick="append()" data-options="iconCls:'icon-add'">新增下级会员</div>
		<div onclick="edit()" data-options="iconCls:'icon-edit'">编辑给类目</div>
		<div onclick="removeIt()" data-options="iconCls:'icon-remove'">删除子类目</div>
		<div class="menu-sep"></div>
		<div onclick="collapse()">收起所有类目</div>
		<div onclick="expand()">展开所有</div>
	</div> -->
<div id="addmember" class="easyui-window" title="添加一个会员"
	data-options="iconCls:'icon-save',closed:'true'"
	style="width: 500px; height: 500px; padding: 5px;">
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center'" style="padding: 10px;">
			<div style="margin-bottom: 20px">
				<div>上级会员名称:</div>
				<input id="parentId" class="easyui-combobox" name="parentId"
					style="width: 100%; height: 30px;"
					data-options="
									url:'./comm/memberlevel',
		        					method:'get',
									valueField:'id',
									textField:'membername' 	">
			</div>
			<div style="margin-bottom: 20px">
				<div>会员名称:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入会员名称'"
					style="width: 100%; height: 32px" id="membername">
			</div>
			<div style="margin-bottom: 20px">
				<div>会员微信号:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入会员微信号'"
					style="width: 100%; height: 32px" id="memberno">
			</div>
			<div style="margin-bottom: 20px">
				<div>登陆密码:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入登陆密码'"
					style="width: 100%; height: 32px" id="password">
			</div>
			<div style="margin-bottom: 20px">
				<div>电话号码:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入电话号码'"
					style="width: 100%; height: 32px" id="tel">
			</div>
			<div style="margin-bottom: 20px">
				<div>职业:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入职业'"
					style="width: 100%; height: 32px" id="job">
			</div>
			<div style="margin-bottom: 20px">
				<div>性别:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入性别'"
					style="width: 100%; height: 32px" id="sex">
			</div>
			<div style="margin-bottom: 20px">
				<div>省份:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入省份'"
					style="width: 100%; height: 32px" id="provice">
			</div>
			<div style="margin-bottom: 20px">
				<div>城市:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入城市'"
					style="width: 100%; height: 32px" id="city">
			</div>
			<div style="margin-bottom: 20px">
			<div>会员推荐码:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入会员推荐码'"
					style="width: 100%; height: 32px" id="vipcode">
			</div>
			<div style="margin-bottom: 20px">
				<div>推广等级:</div>
				<input class="easyui-textbox" data-options="prompt:'请输入推广等级'"
					style="width: 100%; height: 32px" id="level">
			</div>
</div>
<div data-options="region:'south',border:false"
	style="text-align: right; padding: 5px 0 0;">
	<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
		href="javascript:void(0)" onclick="add()" style="width: 80px">Ok</a> <a
		class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
		href="javascript:void(0)" onclick="$('#addmember').window('close')"
		style="width: 80px">Cancel</a>
</div>
</div>
</div>
<script>
var editingId;
function editer(){
	console.log(1)
	if (editingId != undefined){
		$('#member').treegrid('select', editingId);
		return;
	}
	console.log(2)
	var row = $('#member').treegrid('getSelected');
	if (row){
		editingId = row.id
		$('#member').treegrid('beginEdit', editingId);
	}
}

function saver(){
	if (editingId != undefined){
		var t = $('#member');
		t.treegrid('endEdit', editingId);
		var rows = $('#member').datagrid('getChanges');
		console.log(rows)
		rows[0].created = new Date();
		rows[0].updated = new Date();
		$.ajax({	
			 url:'./member/updatefor',
			 method:'post',
			 data:rows[0],
			 success:function(){
				$('#member').datagrid('acceptChanges');
				editIndex = undefined;
				$('#member').datagrid('reload');
			 },
			 error:function(){
					$('#member').datagrid('acceptChanges');
					editIndex = undefined;
				alert("更新失败") 
			 }
		 })
		
		
		editingId = undefined;
	}
}
</script>
<script src="./js/member.js"></script>